package com.wenx.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

import java.util.Date;

public class AppQuartz extends RouteBuilder {

    public static void main(String[] args) throws Exception {

        CamelContext context = new DefaultCamelContext(); // 1. 创建 CamelContext.
        context.addRoutes(new AppQuartz());
        context.setTracing(true);
        context.start(); // 4. 启动CamelContext.
        Thread.sleep(Integer.MAX_VALUE);  // 为了保持CamelContext处于工作状态，这里需要sleep主线程
        context.stop(); // 最后停止CamelContext
    }

    //CronTrigger配置完整格式为： [秒] [分] [小时] [日] [月] [周] [年]
    public void configure() throws Exception {
        Date date = new Date();
        from("quartz://report?cron=5 * * 18-20 * ?&stateful=true")
                .setBody().simple("Current time is "+date+" 11")
                //.bean(reviveProcess.class)
                .to("stream:out");
        from("quartz://report2?cron=5 * 15 18-20 * ?&stateful=true")
                .setBody().simple("Current time is "+date+" 22")
                .to("stream:out");
    }
}
